<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="100">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="100">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="日期"
        width="150">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="150">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--
      分页需要的参数；
        当前页：currentPage
        每页条数：PageSize
        总条数：totals
        current-change事件：只要改变当前页就会触发
    -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="pageSize"
      :current-page="currentPage"
      @current-change="currentChange"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'myVue',
  data () {
    //页面加载完之后，展示数据
    return {
      tableData:[],
      total:0,
      pageSize:10,
      currentPage:5
    }
  },
  methods:{
    //只要改变当前页就会执行
    currentChange(currentPage){//参数就是页面传过来的当前页
      //把页面传的当前页赋值给当前数据模型中
      this.currentPage=currentPage;
      //调用getDepartment(),重新发送请求
      this.getDepartment()
    },

    getDepartment(){//定义方法
      //发送异步请求
      this.$http.post("/dept/list",{"currentPage":this.currentPage})
        .then(result=>{
          console.debug(result)
          this.total=result.data.total
          this.tableData=result.data.rows
        }).catch(result=>{//请求失败了

      })
    }
  },
  mounted(){//调用方法
    this.getDepartment()
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--scoped：作业域 如果加了，样式就只能在当前页生效-->
<style scoped>

</style>
